<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue生命周期</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- 
      四个阶段
      创建  准备响应式数据 create
      挂载  渲染模板 mount
      更新  更新数据,更新视图  update
      销毁  关闭浏览器 destroy

      最重要的两个钩子:
      created  渲染数据
      mounted  操作dom
    -->
    <button @click="count -- ">-</button>
    <span>{{count}}</span>
    <button @click="count ++">+</button>
  </div>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        count: 100
      },
      beforeCreate() {
        console.log(this.count);   //undefined
      },
      created() {
        console.log(this.count);   //100
      },
      brforeMount() {
        console.log(document.querySelector('span'));  //打印不出,因为还没有渲染模板
      },
      mounted() {
        console.log(document.querySelector('span'));  //<span>100</span>
      },

      // 数据修改了,但是没有更新视图
      beforeUpdate() {
        console.log('beforeUpdate');
      },
      // 数据修改了,视图也更新了
      updated() {
        console.log('updated');
      },
      beforeDestory() {
        console.log('卸载前');
        console.log('清除定时器,延时器等等');
      },
      destory() { },
      methods: {

      },
      computed: {

      },
      watch: {

      }
    })
  </script>
</body>

</html>